#import "FlutterEncryptionPlugin.h"
#import "YNEncrypt.h"

@implementation FlutterEncryptionPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"flutter_encryption"
            binaryMessenger:[registrar messenger]];
  FlutterEncryptionPlugin* instance = [[FlutterEncryptionPlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  } else if ([@"encode" isEqualToString:call.method]) {
      NSString *str = [YNEncrypt encryptWithText:call.arguments[@"s"] key:call.arguments[@"k"]];
      result(str);
  } else if ([@"decode" isEqualToString:call.method]) {
      NSString *str = [YNEncrypt decryptWithText:call.arguments[@"s"] key:call.arguments[@"k"]];
      result(str);
  } else if ([@"encode2" isEqualToString:call.method]) {
      NSString *str = [YNEncrypt encryptUseDES:call.arguments[@"s"] key:call.arguments[@"k"]];
      result(str);
  } else if ([@"decode2" isEqualToString:call.method]) {
      NSString *str = [YNEncrypt decryptUseDES:call.arguments[@"s"] key:call.arguments[@"k"]];
      result(str);
  } else {
    result(FlutterMethodNotImplemented);
  }
}

@end
